package com.xiemulei.gulimall.product.api;

import com.xiemulei.common.utils.R;
import com.xiemulei.gulimall.product.entity.CategoryEntity;
import com.xiemulei.gulimall.product.service.CategoryService;
import com.xiemulei.gulimall.product.vo.Catelog2Vo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product")
public class IndexApi {

    @Resource
    CategoryService categoryService;

    @GetMapping("/level1")
    public R indexPage() {
        // 查出所有的一级分类
        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Categories();
        return R.ok().put("level1Categories", categoryEntityList);
    }

    @GetMapping("/catalog")
    public Map<String, List<Catelog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJson();
    }

}
